class TopicController {
  def scaffold = true

  def show = {
    if (!params.offset) params.offset = 0

    def topic = Topic.read(params.id)
    println topic.commitdate
    println topic.lastmod
    
    def comments = Comment.createCriteria().list(max: 10, offset: params.offset, sort: 'id', order: 'asc') {
      eq("topic", topic)
    }
    [topicInstance: topic, comments: comments, total: comments.totalCount]
  }

  def create = {
    def section = Section.get(params.id)
    [section: section]
  }

  def rss = {
    def topic = Topic.read(params.id)
    def comments = Comment.findAllByTopic(topic, [sort: 'id', order: 'asc'])
    //todo: criteria for non-deleted only?

    render(feedType: "rss", feedVersion: "2.0") {
      title = "Linux.org.ru: ${topic.title}"
      link = "http://www.linux.org.ru/"
      description = "Linux.org.ru: ${topic.message}"
      comments.each() {comment ->
        entry(topic.title) {
          link = createLink(controller: 'comment', action: 'show', id: comment.id, absolute: true)
          content(comment.message)
        }
      }
    }
  }

}
